package com.ghost.model
{
	import com.ghost.manager.HDmedia_manager;
	import com.ghost.utils.Debug;
	
	import flash.events.NetStatusEvent;
	import flash.media.SoundTransform;
	import flash.net.NetConnection;
	import flash.net.NetStream;

	public class Media_base
	{
		public var url:String;//media路径
		private var stream_ns:NetStream;
		public var type:String;//media类型
		public var music_type:int;//声音类型0-音乐 1-音效
		public function Media_base()
		{
			trace(this,999999999999,HDmedia_manager.getInstance().connect_nc);
			stream_ns = new NetStream(HDmedia_manager.getInstance().connect_nc);
			stream_ns.client = {};
			stream_ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
		}
		//NetStream对象的状态
		private function netStatusHandler(e:NetStatusEvent):void
		{
			Debug.log(e.info.code);
			//播放结束
			if(e.info.code == 'NetStream.Play.Stop')
			{
				if(music_type==0)play();
				else
				{
					var i:int = HDmedia_manager.getInstance().playing_music_v.indexOf(url);
					if(i!=-1)HDmedia_manager.getInstance().playing_music_v.splice(i,1);
				}
			}
		}
		/**
		 * 播放
		 */		
		public function play():void
		{
			switch(type)
			{
				case "music":
				music_play();
				break;
			}
		}
		
		private function music_play():void
		{
			stream_ns.play(url);
		}
		/**
		 * 停止播放
		 */		
		public function stop():void
		{
			switch(type)
			{
				case "music":
					music_stop();
					break;
			}
		}
		private function music_stop():void
		{
			stream_ns.close();
		}
		/**
		 * media类型不同初始化music是控制音量
		 */		
		public function type_init():void
		{
			switch(type)
			{
				case "music":
				music_init();
				break;
			}
				
		}
		private function music_init():void
		{
			var mySound:SoundTransform = stream_ns.soundTransform;
			mySound.volume = Global_data.music_vol;//更改音量
			stream_ns.soundTransform = mySound;
		}
	}
}